package qhdx.fiveGC.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import qhdx.fiveGC.entity.fiveGc.*;
import qhdx.fiveGC.mapper.FiveGc.*;
import qhdx.fiveGC.service.FiveGcService;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 5GC业务service的实现类
 * @author MI
 * @date 2024-01-12
 */
@Slf4j
@Service
public class FiveGcServiceImpl implements FiveGcService {
    @Resource
    private ResPonOnuZxNumMapper resPonOnuZxNumMapper;
    @Resource
    private ResPonSlkInfoMapper resPonSlkInfoMapper;
    @Resource
    private ResPonWysbInfoMapper resPonWysbInfoMapper;
    @Resource
    private ResPonDomMapper resPonDomMapper;
    @Resource
    private ResPonDbInfoMapper resPonDbInfoMapper;


    @Override
    public FiveGcEntity fiveGcQuery(FiveGcEntity entity) {
        log.info("==========集团5GC-查询-开始===========");
        FiveGcEntity fiveGcEntity = new FiveGcEntity();
        if ("RES_PON_ONU_ZX_NUM".equals(entity.getApiCode())) {
            fiveGcEntity.setResPonOnuZxNumEntity(this.resPonOnuZxNumQuery(entity));
        } else if ("RES_PON_DB".equals(entity.getApiCode())) {
           fiveGcEntity.setResPonDbInfoEntity(this.resPonDbInfoQuery(entity));
        } else if ("RES_PON_SLK_INFO".equals(entity.getApiCode())){
            fiveGcEntity.setResPonSlkInfoEntity(this.resPonSlkInfoQuery(entity));
        } else if ("RES_PON_DOM".equals(entity.getApiCode())) {
            fiveGcEntity.setResPonDomEntity(this.resPonDomQuery(entity));
        } else {
            fiveGcEntity.setResPonWysbInfoEntity(this.resPonWysbInfoQuery(entity));
        }
        log.info("==========集团5GC-查询-结束===========");
        return fiveGcEntity;
    }

    @Override
    public List<ResPonOnuZxNumEntity> resPonOnuZxNumQuery(FiveGcEntity entity) {
        List<ResPonOnuZxNumEntity> list = resPonOnuZxNumMapper.selectList(Wrappers.<ResPonOnuZxNumEntity>lambdaQuery()
                .eq(ResPonOnuZxNumEntity::getApicode, entity.getApiCode())
                .eq(ResPonOnuZxNumEntity::getIp, entity.getIp()));
        log.info("=========集团RES_PON_ONU在线用户数_查询: {}", list);
        return list;
    }

    @Override
    public List<ResPonSlkInfoEntity> resPonSlkInfoQuery(FiveGcEntity entity) {
        List<ResPonSlkInfoEntity> list = resPonSlkInfoMapper.selectList(Wrappers.<ResPonSlkInfoEntity>lambdaQuery()
        .eq(ResPonSlkInfoEntity::getApicode, entity.getApiCode())
        .eq(ResPonSlkInfoEntity::getIp, entity.getIp()));
        for (ResPonSlkInfoEntity x : list) {
            x.setNo("WL202312303495900");
            x.setCode("ZX-PON-EMS");
        }
        log.info("=========集团RES_PON_上联口信息_查询: {}", list);
        return list;
    }

    @Override
    public List<ResPonWysbInfoEntity> resPonWysbInfoQuery(FiveGcEntity entity) {
        List<ResPonWysbInfoEntity> list = resPonWysbInfoMapper.selectList(Wrappers.<ResPonWysbInfoEntity>lambdaQuery()
                .eq(ResPonWysbInfoEntity::getApicode, entity.getApiCode())
                .eq(ResPonWysbInfoEntity::getIp, entity.getIp()));
        log.info("=========集团RES_PON_网元设备信息_查询: {}", list);
        return list;
    }

    @Override
    public List<ResPonDomEntity> resPonDomQuery(FiveGcEntity entity) {
        List<ResPonDomEntity> list = resPonDomMapper.selectList(Wrappers.<ResPonDomEntity>lambdaQuery()
                .eq(ResPonDomEntity::getApicode, entity.getApiCode())
                .eq(ResPonDomEntity::getIp, entity.getIp()));
        log.info("=========集团RES_PON_光模块DDM信息_查询: {}", list);
        return list;
    }

    @Override
    public List<ResPonDbInfoEntity> resPonDbInfoQuery(FiveGcEntity entity) {
        List<ResPonDbInfoEntity> list = resPonDbInfoMapper.selectList(Wrappers.<ResPonDbInfoEntity>lambdaQuery()
                .eq(ResPonDbInfoEntity::getApicode, entity.getApiCode())
                .eq(ResPonDbInfoEntity::getIp, entity.getIp()));
        log.info("=========集团RES_PON_单板信息_查询: {}", list);
        return list;
    }
}
